unit cp_space;

{$IFDEF PFC}
  {$mode delphi}
{$ENDIF}

interface

procedure InitBorders();
procedure InitSpace();

implementation

uses
  zglChipmunk, g_vars;

procedure InitBorders();
const
  te = 1;
  tu = 1;
  stAdd = -1;
var
  stShape: PcpShape;
begin
  //Чан
  stBody := cpBodyNew(INFINITY, INFINITY);
  stShape := cpSegmentShapeNew(stBody, cpv(stAdd, stAdd), cpv(stAdd, SCREEN_HEIGHT - stAdd), 1);
  stShape.e := te;
  stShape.u := tu;
  cpSpaceAddStaticShape(Space, stShape);
  stShape := cpSegmentShapeNew(stBody, cpv(stAdd, SCREEN_HEIGHT - stAdd), cpv(SCREEN_WIDTH - stAdd, SCREEN_HEIGHT - stAdd), 1);
  stShape.e := te;
  stShape.u := tu;
  cpSpaceAddStaticShape(Space, stShape);
  stShape := cpSegmentShapeNew(stBody, cpv(SCREEN_WIDTH - stAdd, SCREEN_HEIGHT - stAdd), cpv(SCREEN_WIDTH - stAdd, stAdd), 1);
  stShape.e := te;
  stShape.u := tu;
  cpSpaceAddStaticShape(Space, stShape);
  //Крышка
  stShape := cpSegmentShapeNew(stBody, cpv(stAdd, stAdd), cpv(SCREEN_WIDTH - stAdd, stAdd), 1);
  stShape.e := te;
  stShape.u := tu;
  cpSpaceAddStaticShape(Space, stShape);
end;

procedure InitSpace();
begin
  Space := cpSpaceNew();
  with Space^ do
  begin
    //Кол-во итераций обработки
    iterations := 10;
    elasticIterations := 10;
    //гравитация
    gravity := cpv(0, 100);
    //коэф затухания движения
//    damping := 0.9;
  end;
end;

end.

